import axios from 'axios'
import settingAPI from '@/setting/setting'

//创建全局配置
const instance = axios.create({
  baseURL: settingAPI.BACK_URL,
  timeout: 5000 //5s
})

// 添加请求拦截器
instance.interceptors.request.use(
  function (config) {
    // 在发送请求之前做些什么
    const AUTH_TOKEN = sessionStorage.getItem('token') || ''
    if (AUTH_TOKEN) {
      ;(config.headers as any).Authorization = AUTH_TOKEN
    }
    return config
  },
  function (error) {
    // 对请求错误做些什么
    return Promise.reject(error)
  }
)
export default instance
